home *** CD-ROM | disk | FTP | other *** search
- /*
- * FLAGSET.CPX
- * Lesen und Setzen von Programmflags
- *
- * Autor: Volker Hemsen, 1993-97
- * Compiler: GNU C/C++
- * Librarys: xlb, gem
- */
-
- /* Includes */
- #include <aesbind.h>
- #include <cpx.h>
- #include <string.h>
- #include <osbind.h>
- #include <xlb.h>
- #include "resource.h"
-
- /* Typen & Strukturen */
- typedef struct
- {
- unsigned tpa_size : 4; /* 28..31 */
- unsigned res1 : 12; /* 16..27 */
- unsigned res2 : 4; /* 12..15 */
- unsigned shared_text : 1; /* 11 */
- unsigned res3 : 3; /* 8..10 */
- unsigned memprotection: 4; /* 4..7 */
- unsigned res4 : 1; /* 3 */
- unsigned fast_malloc : 1; /* 2 */
- unsigned fast_program : 1; /* 1 */
- unsigned fast_load : 1; /* 0 */
- } HEADER_FLAGS;
-
- /* Konstanten */
- #define EXTENSION_MAX 8
-
- /* Prototypen */
- short __saveds __stdargs cpx_call(GRECT*);
- short dopopup(char *items[],short num,short start,short objc);
- boolean file_patch(boolean writemode);
- void load_flags();
-
- /* Objekte in Tree DIAL */
- void drawobjc(short ob)
- {
- drawobjc(DIAL,ob);
- }
- void setobstr(short ob,char* str)
- {
- setobstr(DIAL,ob,str);
- }
- void clrobselect(short ob,boolean draw)
- {
- setobselect(DIAL,ob,FALSE);
- if (draw)
- drawobjc(ob);
- }
- void setobselect(short ob,boolean state,boolean draw)
- {
- register OBJECT *t=&DIAL[ob];
- t->ob_state&=(~CROSSED);
- if (state)
- t->ob_state|=CROSSED;
- if (draw)
- drawobjc(ob);
- }
- inline void setobselect(short ob,unsigned short state,boolean draw)
- {
- setobselect(ob,state?TRUE:FALSE,draw);
- }
-
- /* Variablen */
- XCPB *xcpb;
- char path[PATH_MAX],validpath[PATH_MAX];
- char ext[EXTENSION_MAX]="*";
- HEADER_FLAGS flags;
- CPXINFO cpxinfo={cpx_call,0L,0L,0L,0L,0L,0L,0L,0L,0L};
- char *tpa_items[]={ " 128kB "," 256kB "," 384kB "," 512kB "," 640kB ",
- " 768kB "," 896kB "," 1024kB "," 1152kB "," 1280kB "," 1408kB ",
- " 1536kB "," 1664kB "," 1792kB "," 1920kB "," 2048kB " };
- char *memprot_items[]={ " privat "," global "," super "," lesbar " };
-
- extern "C" {
- CPXINFO* __saveds __stdargs cpx_init(XCPB*);
- CPXINFO* __saveds __stdargs cpx_init(XCPB* Xcpb)
- {
- if (Xcpb->booting)
- return((CPXINFO*)1L);
- xcpb=Xcpb;
- return(&cpxinfo);
- }
- }
-
- short __saveds __stdargs cpx_call(GRECT *rect)
- {
- boolean ende=FALSE;
- {
- register char *p=(char*)xcpb->Get_Buffer();
- if (*p) {
- strcpy(validpath,p);
- strcpy(path,validpath);
- load_flags();
- } else {
- path[0]=Dgetdrv()+65;
- path[1]=':';
- Dgetpath(&path[2],0);
- strcat(path,"\\");
- }
- }
- stcgfn(((TEDINFO*)DIAL[DATEI].ob_spec)->te_ptext,path);
- setobstr(RMTPA,tpa_items[flags.tpa_size]);
- setobstr(MEMPRT,memprot_items[flags.memprotection]);
- DIAL[0].ob_x=rect->g_x;
- DIAL[0].ob_y=rect->g_y;
- objc_draw(DIAL,0,MAX_DEPTH,rect->g_x,rect->g_y,rect->g_w,rect->g_h);
- do {
- short msg[8],ex;
- ex=xcpb->Xform_do(DIAL,0,msg);
- if (ex<0) { // Fenster-Meldungen
- switch(msg[0]) {
- case WM_CLOSED:
- case AC_CLOSE:
- ende=TRUE;
- break;
- }
- } else { // Dialogbox-Meldungen
- switch(ex) {
- case DATEI:
- case LOAD:
- if (fileselector(ext,"Datei auswählen",path))
- load_flags();
- graf_mouse(0,0L); //keine Ahnung warum, aber is so!!!
- clrobselect(LOAD,FALSE);
- drawobjc(0);
- break;
- case FSTLD:
- case FSTLDS:
- flags.fast_load=!flags.fast_load;
- setobselect(FSTLD,flags.fast_load,TRUE);
- break;
- case FSTRMRM:
- case FSTRMRMS:
- flags.fast_malloc=!flags.fast_malloc;
- setobselect(FSTRMRM,flags.fast_malloc,TRUE);
- break;
- case FSTRMLD:
- case FSTRMLDS:
- flags.fast_program=!flags.fast_program;
- setobselect(FSTRMLD,flags.fast_program,TRUE);
- break;
- case SHRDTXT:
- case SHRDTXTS:
- flags.shared_text=!flags.shared_text;
- setobselect(SHRDTXT,flags.shared_text,TRUE);
- break;
- case RMTPA:
- {
- register short ret=dopopup(tpa_items,16,flags.tpa_size,RMTPA);
- if (ret>=0)
- flags.tpa_size=ret;
- }
- break;
- case MEMPRT:
- {
- register short ret=dopopup(memprot_items,4,flags.memprotection,MEMPRT);
- if (ret>=0)
- flags.memprotection=ret;
- }
- break;
- case SAVE:
- file_patch(TRUE);
- clrobselect(SAVE,TRUE);
- break;
- case ENDE:
- ende=TRUE;
- break;
- }
- }
- } while (!ende);
- {
- register char *p=(char*)xcpb->Get_Buffer();
- if (strlen(validpath)<64)
- strcpy(p,validpath);
- else
- *p=0;
- }
- return(0);
- }
-
- void load_flags()
- {
- stcgfe(ext,path);
- if (!*ext)
- strcat(ext,"*");
- if (file_patch(FALSE)) {
- stcgfn(((TEDINFO*)DIAL[DATEI].ob_spec)->te_ptext,path);
- setobselect(FSTLD,(short)flags.fast_load,FALSE);
- setobselect(FSTRMRM,(short)flags.fast_malloc,FALSE);
- setobselect(FSTRMLD,(short)flags.fast_program,FALSE);
- setobselect(SHRDTXT,(short)flags.shared_text,FALSE);
- setobstr(RMTPA,tpa_items[flags.tpa_size]);
- setobstr(MEMPRT,memprot_items[flags.memprotection]);
- }
- }
-
- boolean file_patch(boolean writemode)
- {
- register long fh;
- char *p;
- if (writemode==FALSE)
- p=path;
- else
- p=validpath;
- fh=Fopen(p,2);
- if (fh>=0) {
- if ( (stricmp(ext,"CPX")==0) || (stricmp(ext,"CPZ")==0) )
- Fseek(22L+512,fh,0);
- else
- Fseek(22L,fh,0);
- if (writemode)
- Fwrite(fh,4L,&flags);
- else {
- strcpy(validpath,path);
- Fread(fh,4L,&flags);
- }
- Fclose(fh);
- return TRUE;
- }
- xcpb->XGen_Alert(FILE_NOT_FOUND);
- return FALSE;
- }
-
- short dopopup(char *items[],short num,short start,short objc)
- {
- short ret;
- GRECT gb,gw;
- objc_xywh(DIAL,0,&gw);
- objc_xywh(DIAL,objc,&gb);
- ret=xcpb->Popup(items,num,start,IBM,&gb,&gw);
- if (ret>=0)
- setobstr(objc,items[ret]);
- clrobselect(objc,TRUE);
- return ret;
- }
-